package com.yh.correct.service.impl;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yh.correct.dao.IExpireMapper;
import com.yh.correct.model.CorrectedPerson;
import com.yh.correct.model.Expire;
import com.yh.correct.model.Page;
import com.yh.correct.service.IExpireService;
/**
 * 矫正期满登记服务层实现类
 * 
 * @author 王鹏程 
 * @date 2017.03.14
 * @time 13:37
 */
@Service
public class ExpireServiceImpl implements IExpireService {
	/**
	 * 日志记录
	 */
	private static Logger logger = LogManager.getLogger(ExpireServiceImpl.class);
	/**
	 * 注入矫正期满登记数据访问层接口
	 */
	@Autowired
	private IExpireMapper expireMapper;
	
	/**
	 * 增加期满登记
	 * 
	 * @param expire
	 * @return
	 * @throws Exception 
	 */
	@Override
	public int addExpire(Expire expire) {
		logger.debug("增加期满登记!");
		return expireMapper.addExpire(expire);
	}

	/**
	 * 修改期满登记
	 * 
	 * @param expire
	 * @return
	 * @throws Exception 
	 */
	@Override
	public int editExpire(Expire expire) {
		logger.debug("修改期满登记!");
		return expireMapper.editExpire(expire);
	}

	/**
	 * 删除期满登记
	 * 
	 * @param expire
	 * @return
	 * @throws Exception 
	 */
	@Override
	public int delExpire(Expire expire) {
		logger.debug("删除期满登记!");
		return expireMapper.delExpire(expire);
	}

	/**
	 * 模糊查询期满登记
	 * 
	 * @param condition
	 * @return
	 * @throws Exception 
	 */
	@Override
	public Page queryLikeExpires(Map<String, Object> condition) {
		
		Page page=new Page();
		page.setTotalNum(expireMapper.getLikeExpiresCount(condition));
		int pageSize = Integer.parseInt(String.valueOf(condition.get("pageSize")));
		page.setPageSize(pageSize);
		int curPageNum = Integer.parseInt(String.valueOf(condition.get("pageNum")));
		page.setCurPageNum(curPageNum);
		page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		page.setResult(expireMapper.getLikeExpires(condition));
		logger.debug("模糊查询期满登记!");
		return page;
	}

	/**
	 * 查询单个期满登记
	 * 
	 * @param expire
	 * @return
	 * @throws Exception 
	 */
	@Override
	public Map<String, Object> queryExpires(Expire expire) {
		Map<String, Object> map = expireMapper.getExpires(expire);
		logger.debug("查询单个期满登记!");
		return map;
	}
	/**
	 * 查询所有期满登记
	 * 
	 * @param 
	 * @return
	 * @throws Exception 
	 */
	@Override
	public LinkedList<Map<String, Object>> getAllExpires(Map<String,Object> condition) {
		logger.debug("查询所有期满登记!");
		return expireMapper.getAllExpires(condition);
	}
	/**
	 * 根据矫正单位查询矫正人员信息
	 * 
	 * @param correctedperson
	 * @return
	 */
	@Override
	public List<CorrectedPerson> getPersonByJud(CorrectedPerson correctedperson) {
		
		return expireMapper.getPersonByJud(correctedperson);

	}
	/**
	 *@author Administrator
	 *@注释 :
	 *	根据id查询监管等级
	 */
	@Override
	public Map<String,Object> getIdExpire(int id) throws Exception {
		logger.debug("根据id监管等级! + ExpireServiceImpl");
		return expireMapper.getIdExpire(id);
	}
}
